/**
 * Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */

/*!
 * \file matmul_shape_tiling.h
 * \brief matmul variable manager
 */

#ifndef IMPL_MATMUL_MODULES_MATMUL_SHAPE_TILING_H
#define IMPL_MATMUL_MODULES_MATMUL_SHAPE_TILING_H

#include "../matmul_module.h"

namespace matmul {
template <typename IMPL, const auto &MM_CFG, class INPUT_TYPE, typename = void>
class MatmulShapeTiling {
public:
    __aicore__ inline MatmulTiling<MM_CFG> GetTiling() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_;
    }

    __aicore__ inline int32_t GetLayoutInfoB() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetALayoutInfoB();
    }

    __aicore__ inline int32_t GetLayoutInfoS() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetALayoutInfoS();
    }

    __aicore__ inline int32_t GetLayoutInfoN() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetALayoutInfoN();
    }

    __aicore__ inline int32_t GetLayoutInfoG() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetALayoutInfoG();
    }

    __aicore__ inline int32_t GetLayoutInfoD() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetALayoutInfoD();
    }

    __aicore__ inline int32_t GetBatchNum()
    {
        return MATMUL_CAST_TO_IMPL()->batchA_;
    }

    __aicore__ inline int GetDepth() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetDepthA1();
    }
};

template <typename IMPL, const auto &MM_CFG, class INPUT_TYPE>
class MatmulShapeTiling<IMPL, MM_CFG, INPUT_TYPE, enable_if_t<INPUT_TYPE::TAG == InputTypeTag::B>> {
public:
    __aicore__ inline MatmulTiling<MM_CFG> GetTiling() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_;
    }

    __aicore__ inline int32_t GetLayoutInfoB() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetBLayoutInfoB();
    }

    __aicore__ inline int32_t GetLayoutInfoS() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetBLayoutInfoS();
    }

    __aicore__ inline int32_t GetLayoutInfoN() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetBLayoutInfoN();
    }

    __aicore__ inline int32_t GetLayoutInfoG() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetBLayoutInfoG();
    }

    __aicore__ inline int32_t GetLayoutInfoD() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetBLayoutInfoD();
    }

    __aicore__ inline int32_t GetBatchNum()
    {
        return MATMUL_CAST_TO_IMPL()->batchB_;
    }

    __aicore__ inline int GetDepth() const
    {
        return MATMUL_CONST_PARAM_VAR.tiling_.GetDepthB1();
    }
};

template <typename IMPL, const auto &MM_CFG, class INPUT_TYPE>
class MatmulShapeTiling<IMPL, MM_CFG, INPUT_TYPE, enable_if_t<INPUT_TYPE::TAG == InputTypeTag::C>> {
public:
    __aicore__ inline int32_t GetCLayoutInfoG()
    {
        return MATMUL_PARAM_VAR.tiling_.GetCLayoutInfoG();
    }

    __aicore__ inline int32_t GetCLayoutInfoS2()
    {
        return MATMUL_PARAM_VAR.tiling_.GetCLayoutInfoS2();
    }

    __aicore__ inline int32_t GetCLayoutInfoN()
    {
        return MATMUL_PARAM_VAR.tiling_.GetCLayoutInfoN();
    }

    __aicore__ inline int32_t GetCLayoutInfoB()
    {
        return MATMUL_PARAM_VAR.tiling_.GetCLayoutInfoB();
    }

    __aicore__ inline int32_t GetCLayoutInfoS1()
    {
        return MATMUL_PARAM_VAR.tiling_.GetCLayoutInfoS1();
    }
};

}      // namespace matmul
#endif // IMPL_MATMUL_MODULES_MATMUL_SHAPE_TILING_H
